
@include('admin.public.head')

<div class="ibox-title">
    <h5>老師添加</h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">

        <div class="form-group">
            <label class="col-sm-3 control-label">門店分類：</label>
            <div class="col-sm-9">
                <select class="form-control" name="store_id" id="store_id">
                    <option value="" >請選擇門店</option>
                    @foreach($select_store as $k=>$v)
                        <option value="{{$k}}" @if($select_id == $k) selected="selected" @endif>{{$v}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">教師名稱：</label>
            <div class="col-sm-9">
                <input type="text" name="teacher_name" class="form-control" placeholder="教師名稱" value="{{$result->teacher_name??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">教師頭像：</label>
            <div class="col-sm-9">
                <input type="file" name="teacher_head" class="form-control"  value="">
                <img src="{{$result->teacher_head??''}}" width="300" height="150">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">老師簽欄：</label>
            <div class="col-sm-9">
                <input type="text" name="tab" class="form-control" placeholder="老師簽欄" value="{{$result->tab??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">老師簡介：</label>
            <div class="col-sm-8">
                <script id="synopsis" name="synopsis" type="text/plain" style="height:300px;">{!! $result->synopsis??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>


        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/teacher" class="btn btn-primary" >返回老師列表</a>
            </div>
        </div>
    </form>
</div>

<script>
    var synopsis_content = UE.getEditor('synopsis');

    $('.do').click(function(){
        var form = new FormData();

        var store_id = $('#store_id option:selected').val();
        var teacher_name = $('input[name="teacher_name"]').val();
        var tab = $('input[name="tab"]').val();
        var id = $('input[name="id"]').val();
        var teacher_head = $('input[name="teacher_head"]')[0].files[0];

        var synopsis = synopsis_content.getContent();

        form.append("store_id", store_id);
        form.append("teacher_name", teacher_name);
        form.append("id", id);
        form.append("tab", tab);
        form.append("teacher_head", teacher_head);
        form.append("synopsis", synopsis);

        $.ajax({
            type: 'POST',
            url: '/teacher_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });

</script>
